﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMA.GENTEv1.Dados;

namespace SMA.GENTEv1
{
    public class StatusEndereco
    {
        #region Variaveis Membro
        private int _idStatusEndereco;
        private string _descricao;
        private GENTEEntities _context;
        #endregion

        #region Parametros
        public int IdStatusEndereco
        {
            get { return _idStatusEndereco; }
            set { _idStatusEndereco = value; }
        }
        public string Descricao
        {
            get { return _descricao; }
            set { _descricao = value; }
        }
        #endregion

        #region Construtores
        public StatusEndereco()
        {
            try
            {
                _context = new GENTEEntities();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public StatusEndereco(int idStatus)
        {
            try
            {
                _context = new GENTEEntities();
                Carregar(idStatus);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodos Privados
        private void Carregar(int idStatus)
        {
            try
            {
                var consulta = from se in _context.tab_status_endereco
                               where se.id_status_endereco == idStatus
                               select se;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    this._idStatusEndereco = list.id_status_endereco;
                    this._descricao = list.descricao;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodos Publicos
        public List<StatusEndereco> SelectAll()
        {
            try
            {
                List<StatusEndereco> listStatusEndereco = new List<StatusEndereco>();

                var consulta = from se in _context.tab_status_endereco
                               select se;
                
                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    StatusEndereco statusEndereco = new StatusEndereco();
                    statusEndereco.IdStatusEndereco = list.id_status_endereco;
                    statusEndereco.Descricao = list.descricao;

                    listStatusEndereco.Add(statusEndereco);
                }

                return listStatusEndereco;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}
